import java.util.Scanner;

public class charBinaryTree {

    static class charBinaryTreeNode {
        char val;
        charBinaryTreeNode leftChild;
        charBinaryTreeNode rightChild;

        public charBinaryTreeNode(char val) {
            this.val = val;
        }
    }

    charBinaryTreeNode root;

    public static int i = 0;

    public static charBinaryTreeNode buildTreeNode(String input) {
        //检查i是否超出input的长度
        if(i >= input.length()) {
            return null;
        }
        if(input.charAt(i) == '#') {
            return null;
        }

        charBinaryTreeNode curNode = new charBinaryTreeNode(input.charAt(i));

        i++;
        curNode.leftChild = buildTreeNode(input);
        i++;
        curNode.rightChild = buildTreeNode(input);
        return curNode;
    }

    //中序遍历
    public static void inOrder(charBinaryTreeNode root) {
        if(root == null) {
            return;
        }

        //递归遍历左子树
        inOrder(root.leftChild);
        //输出当前结点的值
        System.out.print(root.val + " ");
        //递归遍历右子树
        inOrder(root.rightChild);
    }

    public static void main(String[] args) {
        String input = "abc##de#g##f###";
        charBinaryTreeNode node = buildTreeNode(input);
        inOrder(node);

    }
}
